/*
 *  三维窗口,设定窥探窗口大小,往里添加模型,运动窗口,截取视图
 */
#ifndef _3D_WINDOW_H_
#define _3D_WINDOW_H_

#include "3d_model.h"
#include "3d_camera.h"
#include "image.h"

class D3Window : public D3Camera
{
public:
    //一张画布绑定一个相机
    D3Window(int32_t width, int32_t height, int32_t far = 1000, int32_t near = -1000);
    ~D3Window();

    //获取窗口视图(默认背景色全透明)
    Image& GetImage(uint32_t color = 0xFF000000);

    //添加模型
    int32_t AddModel(D3Model* model);

private:
    Image image;
    CrossList modelList;
    
    float **depthGrid; //二维深度表
    uint8_t **flagGrid; //二维标记表(用于渲染模型时,防止单个点反复绘制)
    uint8_t flagGridValue = 0; //二维标记表当前值(每绘制一个ModelPart都有一个相同值)

    //颜色清屏
    void Clear(uint32_t color = 0xFF000000);

    //渲染模型
    void Draw();
    //渲染模型部件
    void DrawPart(D3Atom atom, D3ModelPart part);

    //渲染直线
    void D2DrawLine(int32_t *xy, float *depth, uint32_t color);
    //渲染三角形(纯色填充)
    void D2DrawTriangle(int32_t *xy, float *depth, uint32_t color);
    //渲染三角形(图片填充)
    void D2DrawTriangle(int32_t *xy, float *depth, int32_t *xyToFilm, ImageGrid *grid);
    //渲染矩形(纯色填充)
    void D2DrawRect(int32_t *xy, float *depth, uint32_t color);
    //渲染矩形(图片填充)
    void D2DrawRect(int32_t *xy, float *depth, ImageGrid *grid);
};

#endif // _3D_WINDOW_H_
